package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.adapter.CarCheckInfoAdapter;
import com.wqtz.chechai.adapter.TimeAdapter;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.bean.MsgBean;
import com.wqtz.chechai.presenter.BasePresent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/1/20 15:13
 */

public class QuoteDetailActivity extends BaseActivity implements AdapterView.OnItemClickListener, TimeAdapter.itemClickCallBack {
	@BindView(R.id.iv_back)
	ImageView mIvBack;
	@BindView(R.id.tv_title)
	TextView mTvTitle;
	@BindView(R.id.rl_title)
	RelativeLayout mRlTitle;
	@BindView(R.id.tv_carModel)
	TextView mTvCarModel;
	@BindView(R.id.ll_carName)
	LinearLayout mLlCarName;
	@BindView(R.id.tv_preference_price)
	TextView mTvPreferencePrice;
	@BindView(R.id.ll_pre_price)
	LinearLayout mLlPrePrice;
	@BindView(R.id.tv_assume)
	TextView mTvAssume;
	@BindView(R.id.ll_should_pay)
	LinearLayout mLlShouldPay;
	@BindView(R.id.ll_carinfo)
	LinearLayout mLlCarinfo;
	@BindView(R.id.tv_run_km)
	TextView mTvRunKm;
	@BindView(R.id.tv_usetime)
	TextView mTvUsetime;
	@BindView(R.id.tv_car_status)
	TextView mTvCarStatus;
	@BindView(R.id.ll_car_detail_1)
	LinearLayout mLlCarDetail1;
	@BindView(R.id.ll_car_detail_2)
	LinearLayout mLlCarDetail2;
	@BindView(R.id.lv_car_check)
	ListView mLvCarCheck;
	@BindView(R.id.lv_stepview)
	ListView mLvStepview;
	@BindView(R.id.iv_status)
	ImageView mIvStatus;
	@BindView(R.id.tv_status)
	TextView mTvStatus;
	@BindView(R.id.btn)
	Button mBtn;
	@BindView(R.id.bottom_status)
	RelativeLayout mBottomStatus;
	private String carVIN;//车辆VIN码
	private String cityId;//购买地点城市ID
	private String carModelId; //车辆型号对应的ID
	private String carModel;//车辆型号
	private String year; //购买年份
	private String month;//购买月份
	private String mileage;//行驶的公里数
	private String price;//购买的价钱
	private String carStatus; //车辆状态
	private String mortgageStatus;//车辆抵押状态
	private String provinceId; //省份ID
	private String assumPrice; //预估价格
	private String carBuyTime;//车辆购买时间
	private String price1; //个人买卖价
	private String price2;//经销商购入价
	private String price3;//经销商卖出价
	private String shouldPay; //审核通过报价
	private int type; //审核状态
	private final int isPASS = 0;
	private final int isREVIEW = 1;
	private final int isREFUSE = 2;
	private final int isCANCLE = 3;

	private TimeAdapter mTimeAdapter;
	private List<String> mList;
	private List<MsgBean> msgs = new ArrayList<>();
	CarCheckInfoAdapter mAdapter;


	@Override
	public void init() {
		ButterKnife.bind(this);
		Intent intent = getIntent();
		cityId = intent.getStringExtra("cityId");
		provinceId = intent.getStringExtra("provinceId");
		carModelId = intent.getStringExtra("carModelId");
		carModel = intent.getStringExtra("carModel");
		carBuyTime = intent.getStringExtra("buyTime");
		mileage = intent.getStringExtra("mileage");
		carStatus = intent.getStringExtra("carStatus");
		price1 = intent.getStringExtra("price1");
		price2 = intent.getStringExtra("price2");
		price3 = intent.getStringExtra("price3");
		assumPrice = intent.getStringExtra("assumPrice");
		shouldPay = intent.getStringExtra("shouldpay");
		carVIN = intent.getStringExtra("VIN");
		type = intent.getIntExtra("type", -1);
		msgs = (List<MsgBean>) intent.getSerializableExtra("msgs");
		checkItem();

	}

	//动态生成检查项
	private void checkItem() {
		mList = new ArrayList<>();
		mList.add("行驶证");
		mList.add("车辆查档");
		mTimeAdapter = new TimeAdapter(R.layout.item_time_select);
		mTimeAdapter.addData(mList);
		mLvCarCheck.setAdapter(mTimeAdapter);
		mLvCarCheck.setOnItemClickListener(this);
		mAdapter = new CarCheckInfoAdapter(R.layout.item_carcheckinfo);
		mAdapter.addData(msgs);
		mLvStepview.setAdapter(mAdapter);
		mTimeAdapter.setCallBack(this);
	}

	@Override
	public void loadData() {
		mTvCarModel.setText(carModel);
		mTvPreferencePrice.setText(price1 + "万~" + price3 + "万");
		mTvAssume.setText(assumPrice);
		mTvRunKm.setText(mileage);
		mTvUsetime.setText(carBuyTime);
		mTvCarStatus.setText(carStatus);
		switch (type) {
			case isPASS: {
				mIvStatus.setImageResource(R.mipmap.icon_pass);
				String str = "已审核,报价<font color='#AD2928'><normal>" + shouldPay + "</normal></font>";
				mTvStatus.setText(Html.fromHtml(str));
				mBtn.setText("申请放款");
			}
			break;
			case isREVIEW: {
				mIvStatus.setImageResource(R.mipmap.icon_review);
				mTvStatus.setText("审核中");
				mBtn.setText("取消报价");
				mBtn.setBackgroundResource(R.drawable.shape_quote_btn_refuse);
			}
			break;
			case isREFUSE: {
				mIvStatus.setImageResource(R.mipmap.icon_refuse);
				mTvStatus.setText("被拒绝");
				mBtn.setText("再次申请");
				mBtn.setBackgroundResource(R.drawable.shape_quote_btn_refuse);
			}
			break;
			case isCANCLE: {
				mIvStatus.setImageResource(R.mipmap.loan_canceled);
				mTvStatus.setText("已取消");
				mBtn.setText("再次申请");
				mBtn.setBackgroundResource(R.drawable.shape_quote_btn_refuse);
			}
			break;
		}


	}

	@Override
	public int setContentViews() {
		return R.layout.activity_quote_detail;
	}

	@Override
	public BasePresent createPresenter() {
		return null;
	}


	@OnClick({R.id.iv_back, R.id.btn, R.id.ll_carinfo})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.iv_back:
				finish();
				break;
			case R.id.btn:
				if (mBtn.getText().toString().equals("申请放款")) {
					Intent intent = new Intent(this, RequestMoneyActivity.class);
					startActivity(intent);
				}
				break;
			case R.id.ll_carinfo: {
				toCarInfoDetail();
			}
			break;
		}
	}

	private void toCarInfoDetail() {
		Intent intent = new Intent(this, CarInfoDetailActivity.class);
		intent.putExtra("carModel", carModel);
		intent.putExtra("price2", price2);
		intent.putExtra("VIN", carVIN);
		startActivity(intent);

	}


	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

	}

	//查证条目
	@Override
	public void itemClick(int position) {
		switch (position) {
			case 0: {
				Intent intent = new Intent(this,DrivingLicenseViewActivity.class);
				startActivity(intent);
			}
			break;
			case 1: {
				Intent intent = new Intent(this,CarInfoViewActivity.class);
				startActivity(intent);
			}
			break;
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		activitys.add(this); //添加当前的activity
	}


}
